interface AuthProvider {
  isAuthenticated: boolean
  username: null | string
  signin(username: string): Promise<void>
  signout(): Promise<void>
}

/**
 * 处理鉴权
 */
export const fakeAuthProvider: AuthProvider = {
  isAuthenticated: false,
  username: null,

  async signin(username: string) {
    await new Promise(r => setTimeout(r, 3000)) // fake delay
    fakeAuthProvider.isAuthenticated = true
    fakeAuthProvider.username = username
  },

  async signout() {
    await new Promise(r => setTimeout(r, 3000)) // fake delay
    fakeAuthProvider.isAuthenticated = false
    fakeAuthProvider.username = ''
  }
}
